{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [],
   "source": [
    "import time\n",
    "\n",
    "from selenium import webdriver\n",
    "from selenium.webdriver.common.by import By\n",
    "from selenium.webdriver.support.select import Select\n",
    "\n",
    "driver = webdriver.Edge()\n",
    "driver.get(\"https://sahitest.com/demo/iframesTest.htm\")\n",
    "driver.maximize_window() # 页面最大化\n",
    "\n",
    "driver.find_element(By.ID,'checkRecord').clear()\n",
    "driver.find_element(By.ID,'checkRecord').send_keys(\"666\")\n",
    "\n",
    "# 用iframe下标进入iframe 可以用iframe的ID\n",
    "driver.switch_to.frame(0)\n",
    "time.sleep(2)\n",
    "\n",
    "driver.find_element(By.TAG_NAME,'a').click()\n",
    "\n",
    "\n",
    "\n",
    "# 退出当前iframe\n",
    "\"\"\"driver.switch_to.parent_frame()\"\"\"\n",
    "# 回到主页面\n",
    "driver.switch_to.default_content()\n",
    "time.sleep(2)\n",
    "\n",
    "driver.find_element(By.ID,'checkRecord').clear()\n",
    "driver.find_element(By.ID,'checkRecord').send_keys(\"hhh\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-06-15T23:20:57.027314700Z",
     "start_time": "2024-06-15T23:20:49.002078400Z"
    }
   },
   "id": "26edf9dc35eddb01"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "d32e452fada5d18b"
  },
  {
   "cell_type": "markdown",
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "def6c7ebc0309b46"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "initial_id"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
